<?php
session_start();
include ('main_login.php');
include ('mysqlfunctions.php');
?>
<html>
	<head>
		<title>UH Book Selling for Students</title>
		<!-- Bootstrap -->
		<script src="js/bootstrap.min.js"></script>
    	<link href="css/bootstrap.css" rel="stylesheet">
    	<script src="http://code.jquery.com/jquery-latest.js"></script>
    	<script type="text/javascript" src="https://raw.github.com/twitter/bootstrap/master/js/bootstrap-dropdown.js"></script>
    	
		<style>
		html {
			padding: 0;
			margin: 0;
			border-spacing: 0;
			height: 100%;
			width: 100%
		}
		
		div.box { background: #FFF; height: 100%; width: 100%; clear:right;padding: 0px; border-spacing: 0; margin:0}
		div.div1{ background: #FFF; float: left; height: auto; width: 100%; clear:right; border-spacing: 0; padding:0; margin:0 }
		div.div2{ background: #478438; height: 100%; width: 100%; }
		div.clear { clear: both; height: 1px; overflow: hidden; font-size:0pt; margin-top: -1px; }
		
		div.article_img {
		  float:left;
		  width:400px;
		  padding:5px;
		  margin: 5px 20px 5px 0px;
		}

		#box {  
			border-radius: 25px;
			width:650px;
			height:50px;
			border:1px 
			solid black; 
			background: #FFF;          
		}
.no-space [class*="span"] {
    margin-left: 0;
}
		</style>
		
		<script type="text/javascript">
		function convertToPassword() {
			  document.getElementById('mypassword').type="password";
			  alert("Invalid option.");
		}
		</script>
	</head>
	
	<body>
	<div class="box">
	   <div class="div1">
	   	<div class="article_img">
		    <img src="img/logo_comp.jpg" width="300" height="400" alt="logo">
		</div>
		<h1>
		<?php 
		if ( isset( $_SESSION['myusername'] ) ) {
			logout();
		}
		else {
			login();
			if ( isset( $_SESSION['loginerror'] ) ) {
				echo "<script>alert(\"Username or Password is incorrect.\");</script>";
			    unset($_SESSION['loginerror']);
			}	
		}
		?> 
		</h1>
		</div>
		
		<div class="div2">
	   	<canvas id="title" width="1390" height="90"></canvas>
            <script>
              var canvas = document.getElementById('title');
              var context = canvas.getContext('2d');
              var x = canvas.width / 2;
              var y = canvas.height / 2;
              context.font = 'bold 30pt Calibri';
              context.textAlign = 'center';
              context.fillText('Search for a Book', x, y);
            </script>
        <div class="container" >
            
            <form id="search" action="index.php" method="post">
 
                <div class="row">
                    <div class="span4 offset2">
                        <label> <strong> Category </strong> </label>
                        <select id="option" name="option" >
			               	<option value = "bookname">Book</option>
			               	<option value = "class">Class</option>
			               	<option value = "professor">Professor</option>
			               	<option value = "author">Author</option>
			               	<option value = "issn">ISSN</option>
         				</select>    
                	</div>
                    <div class="span4">
                        <label> <strong> Search </strong> </label>
                        <input type="text" style="width: 500px; height: 30px;" id="search" name="search"  width="100" height="45">
                    </div>


                <br>
            </div>
               <div class ="span4 offset4">
                    <input class="btn btn-large btn-block btn-primary" type="submit" id="submit" name="submit" value="Search" />
                </div>
            </form>
            <br>
            <div class="span4 offset2">
            	<?php
					if(isset($_POST['submit'])) {
						$option=$_POST['option'];
						$info=$_POST['search'];
						$con = mysql_connect("mysql2.000webhost.com","a7709402_test","ics414");
						if (!$con)
						  {
						  die('Could not connect: ' . mysql_error());
						  }

						mysql_select_db("a7709402_test", $con) or die("cannot select DB");;

						$result = mysql_query("SELECT * FROM books WHERE $option='$info'");

						if(mysql_num_rows($result) == 0) {
							echo "<br><div id=\"box\"><center style=\"padding-top:12px;\">NO RESULTS</center></a></div>";
						}
						else{
							while($row = mysql_fetch_array($result))
						  {
						  echo "
            					<br>
            					<div id=\"box\">
								<a href=\""; echo $row['url']; echo "\"><center style=\"padding-top:12px;\">";
						  echo $row['bookname'] . " | " . $row['class'] . " | " . "$". $row['price'];
						  echo "</center></a></div>";
						  }
                                                }

						mysql_close($con);
					}
				?>
            </div>
		</div>
		
		<div class="clear">
		</div>
	</body>
</html>
